package com.project.service.impl;
import com.project.bean.ShopCarBean;
import com.project.mapper.IShopCarMapper;
import com.project.service.IShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


@Service
@Transactional
public class ShopCarServiceImpl implements IShopCarService {

    @Autowired
    private IShopCarMapper mapper;

    @Override
    public void add(int userId, int productId) {
       int c= mapper.hasUserShop(userId,productId);
       if (c==0){
           mapper.addShop(userId,productId,1);
       }else {
           mapper.addDeShop(userId,productId,1);
       }
    }

    @Override
    public void update(int id, int num) {
        mapper.updateNum(id, num);
    }

    @Override
    public void del(int id) {
        mapper.del(id);
    }

    @Override
    public List<ShopCarBean> findByUser(int userId) {
        return mapper.findByUser(userId);
    }




}
